/*
 * 验证规则
 * ['change', 'blur'] 修改 或 失去焦点时触发验证
 */
const trigger = ['change', 'blur']
// const trigger = ['blur']
const errorMessage = "非法字符"
// 必填选项
export const requiredVerify = (val) => {
	return {
    required: true,
    message: `请填写${val}`,
    trigger
  }
}
export const lengthVerify = (len) => {
  function verify(rule,value,callback){
    if (String(value).length === len){
      callback()
    }else {
      callback(new Error(`长度应为${len}个字符`))
    }
  }
  return { validator: verify, trigger}
}
// 字符长度范围限制
export const rangeVerify = (min, max) => {
  return {
    min,
    max,
    message: `输入长度为${min}-${max}字符`,
    trigger
  }
}
// 中文字符
export const chinaCharVerify = () => {
	return {
    pattern: /^[\u4e00-\u9fa5]+$/,
    message: errorMessage,
    trigger
  }
}
// 数字
export const numberVerify = () => {
	return {
    pattern: /^[0-9_/.]+$/,
    message: '请输入数字',
    trigger
  }
}

//  非法字符过滤，过滤掉除了字母和数字外的其他字符
export const codeVerify = () => {
	return {
    pattern: /^[a-zA-Z0-9_/]+$/,
    message: errorMessage,
    trigger
  }
}
// 手机号码
export const phoneNumber = () => {
	return {
    pattern: /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/,
    message: "手机号错误",
    trigger
  }
}
